package com.inspinia.base.mq.rabbitmq.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

/**
 * @author Veblen
 */
@Configuration
@PropertySource(value = "classpath:rabbitMq.properties",ignoreResourceNotFound = true)
public class RabbitExchangeConfig {

    /**
     * 直连交换机
     * @return
     */
    @Bean
    public DirectExchange defaultExchange() {
        return new DirectExchange(RabbitConfig.QUEUE_EXCHANGE);
    }

    /**
     * 队列名称
     * @return
     */
    @Bean
    public Queue queue() {
        return QueueBuilder.durable(RabbitConfig.QUEUE).build();
    }

    /**
     * 绑定路由
     * @return
     */
    @Bean
    public Binding binding() {
        return BindingBuilder.bind(this.queue()).to(this.defaultExchange()).with(RabbitConfig.ROUTING_KEY);
    }
}
